package test.org.nanotek.jpa.persistence.person.artist;

import org.nanotek.Builder;
import org.nanotek.base.artist.Artist;
import org.nanotek.base.artist.ArtistType;
import org.nanotek.base.person.name.NamePart;
import org.nanotek.base.person.name.NamePersonType;

import test.org.nanotek.jpa.persistence.person.PersonBuilderException;

public class ArtistBuilder implements Builder<Artist>{

	public Artist artist; 
	private Integer consistence = 0;
	
	public ArtistBuilder()
	{ 
		artist = new Artist();
	}
	
	public ArtistBuilder setFirstName(String value) {
		artist.getNamePerson().getName().add(new NamePart(NamePersonType.GivenName,value));
		consistence = consistence | NamePersonType.GivenName.ordinal();
		return this;
	}


	public void setArtistType(ArtistType artistType) {
		artist.setArtistType(artistType);
	}
	
	public ArtistBuilder setLastName(String value) {
		artist.getNamePerson().getName().add(new NamePart(NamePersonType.LastName,value));
		consistence = consistence | NamePersonType.LastName.ordinal();
		return this;
	}

	public ArtistBuilder setMiddleName(String value) {
		artist.getNamePerson().getName().add(new NamePart(NamePersonType.MiddleName,value));
		return this;
	}

	public ArtistBuilder setTitleName(String value) {
		artist.getNamePerson().getName().add(new NamePart(NamePersonType.TitleName,value));
		return this;
	}

//	@Override
//	public ArtistBuilder setNomenClature(String value) {
//		setNomenClature(value);
//		return this;
//	}
//
//	@Override
//	public ArtistBuilder setComplement(String value) {
//		setComplement(value);
//		return this;
//	}
//
//	@Override
//	public ArtistBuilder setDateBirth(Date dateBirth) {
//		 setDateBirth(dateBirth);
//		 return this;
//	}

	protected void checkConstraint()
	{ 
		int t = (consistence);
		 int ver = (NamePersonType.GivenName.ordinal() | NamePersonType.LastName.ordinal());
		 System.out.println(ver + "  " + t);
		 if (t < ver) 
			 throw new PersonBuilderException("InConsistent Record");
		 System.out.println(t);
	}
	
	@Override
	public Artist build() {
		checkConstraint();
		return artist;
	}

}
